package com.example.demo.controller.impor;

import com.example.demo.dbo.User;
import com.example.demo.signature.PublicUtils;
import com.example.demo.util.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
public class TestJJ {
    public void deleteFile(String type, String filePath) {
//        init();
        try {
            log.info("AwsS3OssService--->deleteFile---type:{},filePath:{},bucket:{}",type,filePath);
            // 删除_bak的文件
            deleteBakFile(type,filePath);
            deleteBak2File(type,filePath);
        } catch (Exception e) {
            log.info("AwsS3OssService--->deleteFile---e:{}",e);
        }
    }

    private void deleteBakFile(String type, String filePath) {
        try {
            int i = 1/0;
        } catch (Exception e) {
            log.info("11111");
        }
    }

    private void deleteBak2File(String type, String filePath) {
        try {
            int i = 1/1;
            System.out.println("我进来了。。。");
        } catch (Exception e) {
            log.info("11111");
        }
    }

    public static void main11(String[] args) {
        TestJJ testJJ = new TestJJ();
        testJJ.deleteFile(null,null);


//        String[] names = {"123.png", "51bOOOPIC5f.mp4", "2m.mp4.MOV332", "未命名3304411"};
//        for (String name : names) {
//            String newName = removeExtension(name);
//            System.out.println("原始名称: " + name + ", 去除后缀后的名称: " + newName);
//        }

//        List<Long> video = new ArrayList<>(Collections.nCopies(8, 1L));
//        List<Long> result = video.stream()
//                .map(num -> num * 8)
//                .collect(Collectors.toList());
//        System.out.println(result);

//        Integer a11 = 1111111111;
//       byte a = 1;
//       if (a == 1) {
//           System.out.println("1");
//       }
//
//        User user = new User();
//        System.out.println(JsonUtil.toJson(user));
//
//        String url = "userUpload/1735982106105323/1735982106105323/picture/95af49f4-6834-48c3-8644-9973a65d000b.png?111";
//        if (url.contains("?")) {
//            url = url.substring(0,url.indexOf("?"));
//        }
//
//        System.out.println(614500/1000);
//        System.out.println(url);
//
//        List<User> list = new ArrayList<>();
//        User user1 = new User();
//        user1.setUserId("1");
//        user1.setName("名称1");
//        list.add(user1);
//        List<User> transcodeList = list.stream().map(item -> {
//            User user2 = new User();
//            user2.setUserId("2");
//            user2.setName("名称2");
//            return user2;
//        }).collect(Collectors.toList());
//
//        System.out.println(JsonUtil.toJson(transcodeList));
    }

    public static String removeExtension(String name) {
        int lastIndex = name.lastIndexOf('.');
        if (lastIndex != -1) {
            return name.substring(0, lastIndex);
        }
        return name;
    }

    public String removeExtension(String sourcePath,String name) {
        String sourceExtension = "";
        if (!StringUtils.isBlank(sourcePath)) {
            int lastIndex = sourcePath.lastIndexOf('.');
            if (lastIndex != -1) {
                sourceExtension =  sourcePath.substring(lastIndex);
            }
        }
        int lastIndex = name.lastIndexOf('.');
        if (lastIndex != -1) {
            String nameExtension = name.substring(lastIndex);
            if(nameExtension.equals(sourceExtension)) {
                return name.substring(0, lastIndex);
            }
        }
        return name;
    }


    public static void main(String[] args) {
        TestJJ testJJ = new TestJJ();
        String southPath = "https://video.people.cn/upload/vod/user1739759454736028/1745670068945326/origin.mp4";
        String name = "中国人民银行：将下调个人住房公积金贷款利率0.25个百分点";
        String s = testJJ.removeExtension(southPath, name);
        String s2 = testJJ.removeExtension(name);

        System.out.println("替换后："+s);
        System.out.println("替换后2："+s2);

//        TestJJ testJJ = new TestJJ();
//        testJJ.deleteFile(null,null);

//      String newKey = "https://video.people.cn/upload/vod/user1735982106105323/1745488143202383/origin_bak.mp4";
//        if (!PublicUtils.isEmptyString(newKey) && newKey.contains("_bak")) {
//            System.out.println("newKey");
//        }

    }
}
